package com.bnlr.lrparking.appui.mine.mycar;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bnlr.lrparking.R;
import com.bnlr.lrparking.base.BaseActivity;
import com.bnlr.lrparking.event.CloseMyCarDetailEvent;
import com.bnlr.lrparking.model.CarM;
import com.bnlr.lrparking.util.GlideImageLoader;
import com.youth.banner.Banner;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/7.
 * 车辆详情
 */
public class MyCarDetailsActivity extends BaseActivity {

    private TextView tvNavTitle;
    private TextView car_number,car_check,cra_type,again_audit;
    private ImageView img_cartype;
    private Banner car_detail_banner;
    private CarM.DataBean carItem;
    private LinearLayout line_type;
    private RelativeLayout car_audit,car_defeated;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car_details);
        initView();
    }

    private void initView() {
        EventBus.getDefault().register(this);
        Intent intent=getIntent();
        carItem= (CarM.DataBean) intent.getSerializableExtra("carDetail");
        tvNavTitle=(TextView)findViewById(R.id.tv_nav_title);
        tvNavTitle.setText("车辆详情");
        car_number=(TextView)findViewById(R.id.car_number);
        car_check=(TextView)findViewById(R.id.car_check);
        cra_type=(TextView)findViewById(R.id.cra_type);
        again_audit=(TextView)findViewById(R.id.again_audit);
        img_cartype=(ImageView) findViewById(R.id.img_cartype);
        car_detail_banner = (Banner) findViewById(R.id.car_detail_banner);
        line_type=(LinearLayout)findViewById(R.id.line_type);
        car_audit=(RelativeLayout)findViewById(R.id.car_audit);
        car_defeated=(RelativeLayout)findViewById(R.id.car_defeated);
            car_number.setText("车牌号：" + carItem.getCarNum());
            cra_type.setText("车辆类型：" + carItem.getCarType());
            List<String> bannerList = new ArrayList<>();
            if (carItem.getPhotoList() != null) {
                for (int i = 0; i < carItem.getPhotoList().size(); i++) {
                    bannerList.add(carItem.getPhotoList().get(i).getPhotoUrl());
                }
                car_detail_banner.setImages(bannerList)
                        .setDelayTime(3000)
                        .setImageLoader(new GlideImageLoader())
                        .start();
            }
            String status = carItem.getStatus();
            if (status.equals("1")) {
                car_check.setText("已审核");
                car_check.setTextColor(getResources().getColor(R.color.main_color));
                img_cartype.setImageResource(R.mipmap.icon_me_check3);
                line_type.setVisibility(View.GONE);
            } else if (status.equals("2")) {
                car_check.setText("审核中");
                car_check.setTextColor(getResources().getColor(R.color.gray03_color));
                img_cartype.setImageResource(R.mipmap.icon_me_check1);
                line_type.setVisibility(View.VISIBLE);
                car_audit.setVisibility(View.VISIBLE);
                car_defeated.setVisibility(View.GONE);
            } else if (status.equals("3")) {
                car_check.setText("审核失败");
                car_check.setTextColor(getResources().getColor(R.color.order_type));
                img_cartype.setImageResource(R.mipmap.icon_me_check2);
                line_type.setVisibility(View.VISIBLE);
                car_audit.setVisibility(View.GONE);
                car_defeated.setVisibility(View.VISIBLE);
            }
        again_audit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MyCarDetailsActivity.this,AddCarActivity.class);
                intent.putExtra("againAudit",carItem);
                startActivity(intent);
            }
        });
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onFinishEvent(CloseMyCarDetailEvent event) {
        finish();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
        car_detail_banner.stopAutoPlay();
        car_detail_banner.releaseBanner();
    }
}
